import { Button } from "antd-mobile";
import React, {
  FC,
  PropsWithChildren,
  useCallback,
  useEffect,
  useState,
} from "react";
import Son from "./son";

const Parent: FC<PropsWithChildren<{}>> = ({ children }) => {
  const [state1, setState1] = useState(0);
  const [state, setState] = useState(0);

  const handle = useCallback(() => {
    // console.log(state);

    // setState((v) => v + 1);
    // 不会触发一直更新。
    setState(state + 1);
  }, [state]);

  useEffect(() => {
    console.log("parent");
  }, [state]);

  const action = useCallback(() => {}, []);

  // const a = (num: number) => {
  //   return num;
  // };

  // const b = async () => {
  //   const bar = await a(1);
  //   console.log(bar);
  // };
  // b();
  return (
    <div>
      <Button onClick={handle}>触发子组件{state}</Button>
      parent
      <Son state1={action}></Son>
      {/* {children} */}
    </div>
  );
};

export default Parent;
